package cn.gson.crm.model.pojos;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "Refund_record", schema = "CRM", catalog = "")
public class RefundRecord {
    private long refundId;
    private Timestamp refundTime;
    private Long refundMoney;
    private String refundDesc;
    private String refundMethod;
    private Order orderByOrderId;
    private Customer customerByCustomerId;
    private MoneyBackPlan moneyBackPlan;
    private Long refundchage;
    private Employee employee;
    @ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH},optional=false)//可选属性optional=false,表示author不能为空。删除文章，不影响用户
    @JoinColumn(name = "refund_chage",insertable = false,updatable = false)//设置在article表中的关联字段(外键)
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }
    @Column(name = "REFUND_CHAGE")
    public Long getRefundchage() {
        return refundchage;
    }

    public void setRefundchage(Long refundchage) {
        this.refundchage = refundchage;
    }

    @OneToOne
    @JoinColumn(name="back_id")
    public MoneyBackPlan getMoneyBackPlan() {
        return moneyBackPlan;
    }

    public void setMoneyBackPlan(MoneyBackPlan moneyBackPlan) {
        this.moneyBackPlan = moneyBackPlan;
    }

    @Id
    @Column(name = "refund_id")
    @GeneratedValue(generator = "seq",strategy = GenerationType.SEQUENCE)
    //定义一个序列生成器
    @SequenceGenerator(name = "seq",sequenceName = "crm",
            initialValue = 1,allocationSize = 1)
    public long getRefundId() {
        return refundId;
    }

    public void setRefundId(long refundId) {
        this.refundId = refundId;
    }

    @Basic
    @Column(name = "refund_time")
    public Timestamp getRefundTime() {
        return refundTime;
    }

    public void setRefundTime(Timestamp refundTime) {
        this.refundTime = refundTime;
    }

    @Basic
    @Column(name = "refund_money")
    public Long getRefundMoney() {
        return refundMoney;
    }

    public void setRefundMoney(Long refundMoney) {
        this.refundMoney = refundMoney;
    }

    @Basic
    @Column(name = "refund_desc")
    public String getRefundDesc() {
        return refundDesc;
    }

    public void setRefundDesc(String refundDesc) {
        this.refundDesc = refundDesc;
    }

    @Basic
    @Column(name = "refund_method")
    public String getRefundMethod() {
        return refundMethod;
    }

    public void setRefundMethod(String refundMethod) {
        this.refundMethod = refundMethod;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RefundRecord that = (RefundRecord) o;
        return refundId == that.refundId &&
                Objects.equals(refundTime, that.refundTime) &&
                Objects.equals(refundMoney, that.refundMoney) &&
                Objects.equals(refundDesc, that.refundDesc) &&
                Objects.equals(refundMethod, that.refundMethod);
    }

    @Override
    public int hashCode() {
        return Objects.hash(refundId, refundTime, refundMoney, refundDesc, refundMethod);
    }

    @ManyToOne
    @JoinColumn(name = "order_id", referencedColumnName = "order_id")
    public Order getOrderByOrderId() {
        return orderByOrderId;
    }

    public void setOrderByOrderId(Order orderByOrderId) {
        this.orderByOrderId = orderByOrderId;
    }

    @ManyToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByCustomerId() {
        return customerByCustomerId;
    }

    public void setCustomerByCustomerId(Customer customerByCustomerId) {
        this.customerByCustomerId = customerByCustomerId;
    }

    @Override
    public String toString() {
        return "RefundRecord{" +
                "refundId=" + refundId +
                ", refundTime=" + refundTime +
                ", refundMoney=" + refundMoney +
                ", refundDesc='" + refundDesc + '\'' +
                ", refundMethod='" + refundMethod + '\'' +
                ", orderByOrderId=" + orderByOrderId +
                ", customerByCustomerId=" + customerByCustomerId +
                ", moneyBackPlan=" + moneyBackPlan +
                ", refundchage=" + refundchage +
                ", employee=" + employee +
                '}';
    }
}
